﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyTestWeb
{
	public partial class MathRadom : System.Web.UI.Page
	{
        static int Num, One, Two;

        static float Err = 0, Right = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            //页面初始化
            TextAnswer.Focus();
            if (!IsPostBack)
            {
                Random r = new Random();
                Num = One = r.Next(1, 100);
                LabelNum.Text = Num.ToString();
                Num = Two = r.Next(1, 100);
                LabelVal.Text = Num.ToString();
            }

        }

        protected void ButtonStart_Click(object sender, EventArgs e)
        {

            LabelMsg.Text = "";
            if (TextAnswer.Text == "")
            {
                LabelMsg.Text = "<b>请输入答案</b>";
                return;
            }
            if (Right + Err == 0) {
                LabelList.Text = "";
                LabelMsg.Text = "";
            }

            if (One + Two == int.Parse(TextAnswer.Text))
            {
                Right++;
                LabelList.Text = LabelList.Text + One.ToString() + "+" +
                    Two.ToString() + "=";
                LabelList.Text = LabelList.Text + TextAnswer.Text +
                    "&nbsp;&nbsp;&nbsp;&nbsp;√" + "<br/>";
            }
            else {
                Err++;
                LabelList.Text = LabelList.Text + One.ToString() + "+" +
                   Two.ToString() + "=";
                LabelList.Text = LabelList.Text + TextAnswer.Text +
                    "&nbsp;&nbsp;&nbsp;&nbsp;×" + "<br/>";
            }
            Random rNum = new Random();
            Num = One = rNum.Next(1, 100);
            LabelNum.Text = Num.ToString();
            Num = Two = rNum.Next(1, 100);
            LabelVal.Text = Num.ToString();
            TextAnswer.Text = "";
            TextAnswer.Focus();
        }

        protected void ButtonEnd_Click(object sender, EventArgs e)
        {
            LabelMsg.Text = "";
            float Sum = Right + Err;
            float Result = Right / Sum * 100;
            LabelMsg.Text = "<b>共同完成</b>" + Sum.ToString() + "题正确: "
                + Right.ToString() + "题,错误";
            LabelMsg.Text = LabelMsg.Text + Err.ToString() + "题,得分:  "
                + Result.ToString();
            Err = Right = 0;
        }
    }   
}